//
//  GeneratorQRCodeViewController.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/5/5.
//  Copyright © 2017年 个人. All rights reserved.
//  生成二维码

import UIKit
import CoreImage
import SVProgressHUD

class GeneratorQRCodeViewController: UIViewController {

    @IBOutlet weak var qrCodeImgaView: UIImageView!
    @IBOutlet weak var inputTextView: UITextView!
    @IBAction func generatorQRCodeButtonmClick() {
        
        // MARK:- 获得data类型的字符
        // 1将输入的字符串转成data类型的数据
        let str = inputTextView.text
        if str == "" {
            SVProgressHUD.showError(withStatus: "请输入内容")
            return
        }
        qrCodeImgaView.image = TWQRCodeTool.generatorQRCode(inputStr: str!, center: "IMG_1518.JPG")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension GeneratorQRCodeViewController : UITextViewDelegate {
    // 把回车键当做退出键盘的响应键
    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        if text == "\n" {
            textView.resignFirstResponder()
            generatorQRCodeButtonmClick()
            return false
        }
        return true
    }
}

